/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhouyou.view.segmentedbar.demo.slice;

import com.zhouyou.view.segmentedbar.*;
import com.zhouyou.view.segmentedbar.demo.AboutAbility;
import com.zhouyou.view.segmentedbar.demo.ResourceTable;
import com.zhouyou.view.segmentedbar.demo.TestAbility;
import com.zhouyou.view.segmentedbar.demo.custom.CustomToolbar;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import java.util.ArrayList;
import java.util.List;

public class MainAbilitySlice extends AbilitySlice {
    DirectionalLayout javaCodeLayout, sideStyleLayout, segmentTextStyleLayout;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        javaCodeLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_java_code_layout);
        sideStyleLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_side_style_layout);
        segmentTextStyleLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_segment_text_style_layout);
        Button more_btn = (Button) findComponentById(ResourceTable.Id_more_btn);
        CustomToolbar toolbar = (CustomToolbar) findComponentById(ResourceTable.Id_injecttoolbar);
        ShapeElement background = new ShapeElement(getContext(), ResourceTable.Graphic_ms__drawable);
        background.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#4050B5")));
        toolbar.setBackground(background);

        createNormalBarViewByXml();
        createNormalBarView();
        createBarViewWithBuilder();
        createBarViewRuleByAvage();
        createBarViewRuleByScal();
        createBarViewWithoutNumericValue();
        createBarViewWithCustomSettings();
        createBarViewWithManySegments();
        createBarViewWithNoSegments();
        createNormalBarViewSideStyleRounded();
        createNormalBarViewSideStyleNormal();
        createNormalBarViewSideStyleAngle();
        createNormalBarViewWithOneSidedSideText();
        createNormalBarViewWithTwoSidedSideText();
        createNormalBarViewWithValueUnit();
        createNormalBarViewWithValueTxt();
        createBarViewWithBgColors();
        createBarViewWithWaterSliderType();
        createBarViewWithOilSliderType();
        createBarViewWithOilSliderType2();
        createBarViewWithOilSliderType3();
        createBarViewWithOilSliderType4();
        createBarViewWithOilSliderType5();
        createBarViewWithOilSliderType6();
        createBarthumb4();
        more_btn.setClickedListener(component -> onMore());

        ArrayList<String> strings = new ArrayList<>();
        strings.add("关于我");
        toolbar.setMenuData(strings);
        toolbar.setTitle("分段控件");
        toolbar.setPopupItemOnClickInterface(() -> toolbar.setMenuOnItemSelectedListener(new CustomToolbar.OnMenuItemSelectedListener() {
            @Override
            public void onMenuItemSelected(int position) {
                switch (position) {
                    case 0:
                        Intent intent1 = new Intent();
                        Intent.OperationBuilder operationBuilder = new Intent.OperationBuilder();
                        operationBuilder.withAbilityName(AboutAbility.class);
                        operationBuilder.withBundleName(getBundleName());
                        operationBuilder.build();
                        intent1.setOperation(operationBuilder.build());
                        startAbility(intent1);
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onMenuNothingSelected() {
            }
        }));
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    // 通过xml配置BarView
    public void createNormalBarViewByXml() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_xml_bar_view);
        final ArrayList<Segment> segments = new ArrayList<>();
        segments.add(new Segment(0, 50, "正常", 0xFFFF0000));
        segments.add(new Segment(50, 100, "严重", 0xFF0000FF));
        barView.setValue(30f);
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setSegments(segments);
    }

    // 通过代码添加SegmentedBarView
    private void createNormalBarView() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 10.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(10.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(20.0f,"20 10¹²/l");
        barView.setSegments(segments);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setValueSignSize(300, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setHeight(201);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        javaCodeLayout.addComponent(barView);
    }

    // 通过代码添加（build方式）
    private void createBarViewWithBuilder() {
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        SegmentedBarView barView = SegmentedBarView.builder(this)
                .segments(segments)
                .value(5.25f)
                .showDescriptionText(true)
                .sideStyle(SegmentedBarViewSideStyle.ANGLE)
                .build();
        barView.setValue(5.25f,"5.25 ml²");
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(273);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setValueSignSize(300, 80);
        barView.setValueSignRound(15);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        javaCodeLayout.addComponent(barView);
    }

    // 分段规则-均分
    public void createBarViewRuleByAvage() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_rule_avage_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 9.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(9.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(13.96f, "13.96 10¹²/l");
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setSegments(segments);
    }

    // 分段规则-比例分配
    public void createBarViewRuleByScal() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_rule_scal_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 9.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(9.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(13.96f, "13.96 10¹²/l");
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setSegments(segments);
    }

    // 非数字分段 只支持均分 默认均分
    public void createBarViewWithoutNumericValue() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_without_numeric_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment("Negative Left", null, Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment("Positive", null, Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment("Negative Right", null, Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValueSegment(1);
        barView.setValueSegmentText("Your result");
        barView.setUnit("ml<sup>2</sup>");
        barView.setShowDescriptionText(false); // 不显示描述文字
        barView.setBarHeight(72);
        barView.setHeight(207);
        barView.setSegments(segments);
    }

    // 自定义设置
    private void createBarViewWithCustomSettings() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_custom_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 30f, "Bad", Color.getIntColor("#2C3E50"));
        segments.add(segment);
        Segment segment2 = new Segment(30f, 70f, "Ok", Color.getIntColor("#5F91A6"));
        segments.add(segment2);
        Segment segment3 = new Segment(70f, 120f, "Good", Color.getIntColor("#ED8C2B"));
        segments.add(segment3);
        Segment segment4 = new Segment(120f, 180f, "Perfect", Color.getIntColor("#911146"));
        segments.add(segment4);
        barView.setValueSignColor(Color.getIntColor("#1A5717"));
        barView.setValue(90f);
        barView.setBarHeight(60);
        barView.setSegments(segments);
        barView.setValueTextSize(60);
        barView.setDescriptionTextSize(30);
        barView.setValueTextColor(Color.getIntColor("#aaffaa"));
        barView.setSegmentTextColor(Color.getIntColor("#999999"));
        barView.setDescriptionTextColor(Color.getIntColor("#aa5555"));
        barView.setGapWidth(0);
        barView.setShowDescriptionText(true);
        barView.setSegmentSideRule(SegmentedBarViewSideRule.SCALE);
        barView.setPadding(0, 6, 0, 0);
        barView.setHeight(295);
    }

    // 众多分段
    private void createBarViewWithManySegments() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_many_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 20f, "Low", Color.getIntColor("#EF3D2F"));
        Segment segment2 = new Segment(20f, 50f, "Optimal", Color.getIntColor("#8CC63E"));
        Segment segment3 = new Segment(50f, 100f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        segments.add(segment2);
        segments.add(segment3);
        barView.setValue(13f);
        barView.setBarHeight(72);
        barView.setHeight(207);
        barView.setSegments(segments);
    }

    // 空分段
    private void createBarViewWithNoSegments() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_empty_bar_view);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(90);
    }

    // bar条样式-圆角
    private void createNormalBarViewSideStyleRounded() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m");
        barView.setSideTextStyle(SegmentedBarViewSideTextStyle.TWO_SIDED);
        barView.setSideStyle(SegmentedBarViewSideStyle.ROUNDED);
        barView.setSegments(segments);
        barView.setShowDescriptionText(false);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(201);
        barView.setValueSignSize(180, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setValueTextSize(40);
        barView.setGapWidth(5);
        barView.setSegmentTextSize(40);
        sideStyleLayout.addComponent(barView);
    }

    // bar条样式-正常
    private void createNormalBarViewSideStyleNormal() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m");
        barView.setSideTextStyle(SegmentedBarViewSideTextStyle.TWO_SIDED);
        barView.setSideStyle(SegmentedBarViewSideStyle.NORMAL);
        barView.setSegments(segments);
        barView.setShowDescriptionText(true);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(273);
        barView.setValueSignSize(180, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        barView.setSegmentTextSize(40);
        sideStyleLayout.addComponent(barView);
    }

    // bar条样式-三角
    private void createNormalBarViewSideStyleAngle() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m");
        barView.setSideTextStyle(SegmentedBarViewSideTextStyle.TWO_SIDED);
        barView.setSideStyle(SegmentedBarViewSideStyle.ANGLE);
        barView.setSegments(segments);
        barView.setShowDescriptionText(true);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(273);
        barView.setValueSignSize(180, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        barView.setSegmentTextSize(40);
        sideStyleLayout.addComponent(barView);
    }

    // Segment文字样式---ONE_SIDED
    private void createNormalBarViewWithOneSidedSideText() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m");
        barView.setSideTextStyle(SegmentedBarViewSideTextStyle.ONE_SIDED); // 可以通过xml配置
        barView.setSegments(segments);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(201);
        barView.setValueSignSize(180, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        barView.setSegmentTextSize(40);
        segmentTextStyleLayout.addComponent(barView);
    }

    // Segment文字样式---TWO_SIDED
    private void createNormalBarViewWithTwoSidedSideText() {
        SegmentedBarView barView = new SegmentedBarView(this);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m");
        barView.setSideTextStyle(SegmentedBarViewSideTextStyle.TWO_SIDED); // 可以通过xml配置
        barView.setSegments(segments);
        barView.setLayoutConfig(new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT));
        barView.setPadding(0, 6, 0, 0);
        barView.setBarHeight(72);
        barView.setHeight(201);
        barView.setValueSignSize(180, 80);
        barView.setValueSignRound(15);
        barView.setArrowHeight(15);
        barView.setArrowWidth(23);
        barView.setGapWidth(5);
        barView.setValueTextSize(40);
        barView.setSegmentTextSize(40);
        segmentTextStyleLayout.addComponent(barView);
    }

    // 设置显示进度-数字、单位
    private void createNormalBarViewWithValueUnit() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_unit_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Some text", "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f,"4.96 m⁵/s²");
        barView.setSegments(segments);
        barView.setShowDescriptionText(true);
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setSideStyle(SegmentedBarViewSideStyle.ANGLE);
    }

    // 设置显示进度-中文
    private void createNormalBarViewWithValueTxt() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_value_txt_bar_view);
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, "Low", Color.getIntColor("#EF3D2F"));
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, "Some text", "Optimal", Color.getIntColor("#8CC63E"));
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, "High", Color.getIntColor("#EF3D2F"));
        segments.add(segment3);
        barView.setValue(4.96f, "正常"); // 显示的时候用“正常代替” 4.96f
        barView.setSegments(segments);
        barView.setShowDescriptionText(true);
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setSideStyle(SegmentedBarViewSideStyle.ANGLE);
    }

    // 设置渐变背景
    private void createBarViewWithBgColors() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_bg_colors_bar_view);
        int colors[] = new int[]{Color.getIntColor("#00e4ff"), Color.getIntColor("#00aeff"), Color.getIntColor("#0172ff")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment = new Segment(0, 4.5f, colors[0]).setDescriptionText("一般");
        segments.add(segment);
        Segment segment2 = new Segment(4.5f, 6.5f, colors[1]).setDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(6.5f, 20f, colors[2]).setDescriptionText("槽糕");
        segments.add(segment3);
        barView.setValue(4.96f); // 显示的时候用“正常代替” 4.96f
        barView.setSegments(segments);
        barView.setBarHeight(72);
        barView.setHeight(279);
        barView.setShowDescriptionText(true);
    }

    // 设置滑块类型
    private void createBarViewWithWaterSliderType() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_water);
        int colors[] = new int[]{Color.getIntColor("#00e4ff"), Color.getIntColor("#00aeff"), Color.getIntColor("#0172ff")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 40.0f, "", colors[0]).setDescriptionText("00").setTopDescriptionText("缺水");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(40.0f, 60.0f, "", colors[1]).setDescriptionText("40%&60%").setTopDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(60.0f, 100.0f, "", colors[2]).setDescriptionText("99.9%").setTopDescriptionText("湿润");
        segments.add(segment3);
        barView.setShowDescriptionText(true);
        barView.setBarHeight(45);
        barView.setHeight(192);
        barView.setValue(30.0f);
        barView.setSegments(segments);
    }

    // 设置滑块类型
    private void createBarViewWithOilSliderType() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_oil);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a"), Color.getIntColor("#72ab2a")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 40.0f, "", colors[0]).setDescriptionText("00").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(40.0f, 60.0f, "", colors[1]).setDescriptionText("40%&60%").setTopDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(60.0f, 100.0f, "", colors[2]).setDescriptionText("99.9%").setTopDescriptionText("偏油");
        segments.add(segment3);
        barView.setShowDescriptionText(true);
        barView.setValue(80.0f);
        barView.setBarHeight(45);
        barView.setHeight(192);
        barView.setSegments(segments);
    }

    private void createBarViewWithOilSliderType2() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_oil2);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a"), Color.getIntColor("#72ab2a"), Color.YELLOW.getValue()};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 30.0f, "", colors[0]).setDescriptionText("").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(30.0f, 50.0f, "", colors[1]).setDescriptionText("52.1%&63.2%").setTopDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(60.0f, 80.0f, "", colors[2]).setDescriptionText("&80.3%").setTopDescriptionText("偏油");
        segments.add(segment3);
        Segment segment4 = new Segment(80.0f, 100.0f, "", colors[3]).setDescriptionText("").setTopDescriptionText("严重");
        segments.add(segment4);
        barView.setShowDescriptionText(true);
        barView.setValue(70.0f);
        barView.setBarHeight(45);
        barView.setHeight(192);
        barView.setSegments(segments);
    }

    private void createBarViewWithOilSliderType3() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_oil3);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a"), Color.getIntColor("#72ab2a"), Color.YELLOW.getValue(), Color.RED.getValue()};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 20.0f, "", colors[0]).setDescriptionText("").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(20.0f, 45.0f, "", colors[1]).setDescriptionText("52.1%&63.2%").setTopDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(45.0f, 60.0f, "", colors[2]).setDescriptionText("&70.3%").setTopDescriptionText("偏油");
        segments.add(segment3);
        Segment segment4 = new Segment(60.0f, 80.0f, "", colors[3]).setDescriptionText("&80.2%").setTopDescriptionText("严重");
        segments.add(segment4);
        Segment segment5 = new Segment(80.0f, 100.0f, "", colors[4]).setDescriptionText("").setTopDescriptionText("糟糕");
        segments.add(segment5);
        barView.setShowDescriptionText(true);
        barView.setValue(55.0f);
        barView.setBarHeight(45);
        barView.setHeight(192);
        barView.setSegments(segments);
    }

    // 设置滑块类型
    private void createBarViewWithOilSliderType4() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_oil4);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 40.0f, "", colors[0]).setDescriptionText("").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(40.0f, 100.0f, "", colors[1]).setDescriptionText("40%&").setTopDescriptionText("正常");
        segments.add(segment2);
        barView.setShowDescriptionText(true);
        barView.setValue(60.0f);
        barView.setBarHeight(45);
        barView.setHeight(192);
        barView.setSegments(segments);
    }

    // 设置滑块类型
    private void createBarViewWithOilSliderType5() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_oil5);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 40.0f, "", colors[0]).setDescriptionText("00").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(40.0f, 100.0f, "", colors[1]).setDescriptionText("40%&100%").setTopDescriptionText("正常");
        segments.add(segment2);
        barView.setShowDescriptionText(true);
        barView.setValue(60.0f);
        barView.setBarHeight(45);
        barView.setHeight(120);
        barView.setSegments(segments);
    }

    // 设置滑块类型
    private void createBarViewWithOilSliderType6() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_thumb);
        int colors[] = new int[]{Color.getIntColor("#a8db62"), Color.getIntColor("#8bc93a"), Color.getIntColor("#72ab2a")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment(0.0f, 15.0f, "", colors[0]).setDescriptionText("00").setTopDescriptionText("缺油");
        segments.add(segment1);
        // 中间显示用40%&60%  “&” 分割
        Segment segment2 = new Segment(15.0f, 45.0f, "", colors[1]).setDescriptionText("15.0%&45.0%").setTopDescriptionText("正常");
        segments.add(segment2);
        Segment segment3 = new Segment(45.0f, 100.0f, "", colors[2]).setDescriptionText("100%").setTopDescriptionText("严重");
        segments.add(segment3);
        barView.setShowDescriptionText(true);
        barView.setValue(14.5f);
        barView.setBarHeight(15);
        barView.setHeight(192);
        barView.setSegments(segments);
    }

    // 设置滑块类型 --非数字分段
    private void createBarthumb4() {
        final SegmentedBarView barView = (SegmentedBarView) findComponentById(ResourceTable.Id_slider_type_bar_view_thumb4);
        int colors[] = new int[]{Color.getIntColor("#fae8d7"), Color.getIntColor("#f3d0c0"), Color.getIntColor("#deb1a0")
                , Color.getIntColor("#cda485"), Color.getIntColor("#bc9375"), Color.getIntColor("#8a6145")};
        ArrayList<Segment> segments = new ArrayList<>();
        Segment segment1 = new Segment("", "亮白", colors[0]);
        segments.add(segment1);
        Segment segment2 = new Segment("", "红润", colors[1]);
        segments.add(segment2);
        Segment segment3 = new Segment("", "自然", colors[2]);
        segments.add(segment3);
        Segment segment4 = new Segment("", "小麦", colors[3]);
        segments.add(segment4);
        Segment segment5 = new Segment("", "暗哑", colors[4]);
        segments.add(segment5);
        Segment segment6 = new Segment("", "黝黑", colors[5]);
        segments.add(segment6);
        barView.setShowDescriptionText(true);
        barView.setValueSegment(4);
        barView.setHeight(225);
        barView.setBarHeight(45);
        barView.setSegments(segments);
    }

    public void onMore() {
        Intent intent = new Intent();
        Intent.OperationBuilder operationBuilder = new Intent.OperationBuilder();
        operationBuilder.withAbilityName(TestAbility.class);
        operationBuilder.withBundleName(getBundleName());
        operationBuilder.build();
        intent.setOperation(operationBuilder.build());
        startAbility(intent);
    }

}

